package com.bd.learning.shift;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

/**
 * 
 */
public class T1 {

    private static Log log = LogFactory.get();

    public static void main(String[] args) {
        //
        t1();
        // t2();
        // t3();
        // t4();
    }

    /**
     * int a左移b位，如果b> 32,这 b=b%32 取余。 左移结果 a * 2(b次方)，如果int越界，舍弃高位
     */
    private static void t1() {
        long a = 5L << 29;
        int b = (int)a;
        log.info(" long a = {} , int b = {} ", a, b);
        log.info("long a = {}", Long.toBinaryString(a));

        log.info("Integer.MAX_VALUE = {} ", Integer.MAX_VALUE);
        log.info("5 << 1 = {} ", 5 << 1);
        log.info("5 << 2 = {} ", 5 << 2);
        log.info("5 << 3 = {} ", 5 << 3);
        log.info("5 << 27 = {} ", 5 << 27);
        log.info("5 << 29 = {} ", 5 << 29);
        log.info("5 << 30 = {} ", 5 << 30);
        log.info("5 << 31 = {} ", 5 << 31);
        log.info("5 << 32 = {} ", 5 << 32);
        log.info("5 << 33 = {} ", 5 << 33);
    }

    private static void t2() {

        log.info("5 >> 1 = {} ", 5 >> 1);
        log.info("5 >> 2 = {} ", 5 >> 2);
        log.info("5 >> 3 = {} ", 5 >> 3);
        log.info("5 >> 31 = {} ", 5 >> 31);
        log.info("5 >> 32 = {} ", 5 >> 32);
        log.info("5 >> 33 = {} ", 5 >> 33);

    }

    private static void t3() {

        log.info("5L << 1 = {} ", 5L << 1);
        log.info("5L << 2 = {} ", 5L << 2);
        log.info("5L << 3 = {} ", 5L << 3);
        log.info("5L << 31 = {} ", 5L << 31);
        log.info("5L << 32 = {} ", 5L << 32);
        log.info("5L << 33 = {} ", 5L << 33);
    }

    private static void t4() {

        log.info("5L >> 1 = {} ", 5L >> 1);
        log.info("5L >> 2 = {} ", 5L >> 2);
        log.info("5L >> 3 = {} ", 5L >> 3);
        log.info("5L >> 31 = {} ", 5L >> 31);
        log.info("5L >> 32 = {} ", 5L >> 32);
        log.info("5L >> 33 = {} ", 5L >> 33);

    }

}
